package com.ruoyi.ljx.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalTime;

/**
 * @author : ljx
 * @date : 2024-12-19 09:35
 * @description :
 **/

@RestController
//@CrossOrigin(origins = {"http://example.com", "http://localhost:8080"}, allowCredentials = "true")
@RequestMapping("/expense")
public class FareController {

    @Autowired
    private DidiFareCalculator didiFareCalculator;

    /**
     * 计算滴滴打车费用
     */
    @PostMapping("/calculate")
    public AjaxResult calculateFare(
            @RequestParam double distance,
            @RequestParam int time,
            @RequestParam int waitTime,
            @RequestParam int startHour,
            @RequestParam int startMinute) {

        LocalTime startTime = LocalTime.of(startHour, startMinute);
        double totalFare = didiFareCalculator.calculateTotalFare(distance, time, waitTime, startTime);
        return AjaxResult.success(totalFare);
    }
}